package co.edu.usbcali.adt.stacks.exercises;

import java.util.Scanner;
import java.util.Stack;

public class Palindrome {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		System.out.println("Write a word to check for palindrome:");
		String word=scanner.next();
		String answer=isPalindrome(word)? " is":" isn't";
		System.out.println(word+answer+" palidrome");
	}
	
	public static boolean isPalindrome(String word){
		Stack<Character> s1=new Stack<Character>();
		Stack<Character> s2=new Stack<Character>();
		int length=word.length();
		for(int i=0;i<length;i++){
			s1.push(word.charAt(i));
		}
		for(int i=0;i<length/2;i++){
			s2.push(s1.pop());
		}
		if(length%2==1){
			s1.pop();
		}
		while(!s1.empty()){
			if(s1.pop()!=s2.pop()){
				return false;
			}
		}
		return true;
	}

}
